/*
 * Copyright 2006-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.martinimix.web.servlet.handler.bluemartini;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * Provides a request wrapper that blocks Blue Martini from screwing with
 * the request payload.  Methods are overridden to prevent Blue Martini
 * from interfering with the container's POST parameter handling.
 * 
 * @author Scott Rossillo
 *
 */
final class BlueMartiniDamageControlHttpServletRequestWrapper extends
		HttpServletRequestWrapper {

	/**
	 * Constructs a new servlet request wrapper.
	 * 
	 * @param request the <code>HttpServletRequest</code> to be wrapped
	 */
	public BlueMartiniDamageControlHttpServletRequestWrapper(HttpServletRequest request) {
		
		super(request);
	}
	
	/**
	 * Always returns zero.
	 * 
	 * @return <code>0</code>
	 */
	public int getContentLength() {
		
		return 0;
	}

	/**
	 * Returns an empty input stream.
	 * 
	 * @see javax.servlet.ServletRequestWrapper#getInputStream()
	 */
	public ServletInputStream getInputStream() throws IOException {
		
		return new ServletInputStream() {
			public int read() throws IOException { return -1; }
		};
	}

	/**
	 * Returns an empty reader.
	 * 
	 * @see javax.servlet.ServletRequestWrapper#getReader()
	 */
	public BufferedReader getReader() throws IOException {
		
		return new BufferedReader(new StringReader(""));
	}
	
}
